﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DiscoveryLogic.DataViz.NetworkDiagram.NetworkData;

namespace DiscoveryLogic.DataViz.NetworkDiagram.LinkerControls
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class LinkDataStat
    {
        private int _TotalLinks;
        /// <summary></summary>
        public int TotalLinks
        {
            get
            {
                return this._TotalLinks;
            }
            set
            {
                this._TotalLinks = value;
            }
        }

        private double? _MaxDistance;
        /// <summary></summary>
        public double? MaxDistance
        {
            get
            {
                return this._MaxDistance;
            }
            set
            {
                this._MaxDistance = value;
            }
        }

        private double? _MinDistance;
        /// <summary></summary>
        public double? MinDistance
        {
            get
            {
                return this._MinDistance;
            }
            set
            {
                this._MinDistance = value;
            }
        }

        private double? _AvgDistance;
        /// <summary></summary>
        public double? AvgDistance
        {
            get
            {
                return this._AvgDistance;
            }
            set
            {
                this._AvgDistance = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="netLinks"></param>
        /// <returns></returns>
        public static LinkDataStat ReadLinkStat(List<LinkDataObject> netLinks)
        {
            LinkDataStat stat=new LinkDataStat();
            double? max = null;
            double? min = null;
            double? avg = null;
            int count = 0;
            if(netLinks !=null && netLinks.Count>0)
            {
                count = netLinks.Count;
                double sum = 0;
                foreach(LinkDataObject link in netLinks)
                {
                    if(!max.HasValue)
                        max = link.Distance;
                    else if(link.Distance>max)
                        max = link.Distance;
                    if(!min.HasValue)
                        min = link.Distance;
                    else if(link.Distance <min)
                        min = link.Distance;
                    sum += link.Distance;
                }
                avg = sum/count;
            }
            stat.AvgDistance = avg;
            stat.MaxDistance = max;
            stat.MinDistance = min;
            stat.TotalLinks = count;
            return stat;
        }
    }
}
